/**
 * 扎鸟窗口逻辑
 * Created by duwei on 2018/4/26.
 */
var Ma_ZhaNiaoWindow = Window.extend({
    _ccsFileName :res.Ma_ZhaNiaoWindow_json,
    initWindow: function (data, timeout, callback) {
        this._super();
        this._initZhaNiaoWindow(data, timeout, callback);
    },
    _initZhaNiaoWindow: function (data, timeout, callback) {
        var self = this;
        for (var i = 0; i < 6; i++) {
            self._nodeList['root.' + i].setOpacity(0);
        }
        var A = 0.1, B = 0.2;
        var uid = data['uid'];
        var playerInfo = gameData.getPlayerInfoByUid(uid);
        var nickname = playerInfo ? ellipsisStr(_.trim(decodeURIComponent(playerInfo.nickname)), 6) : '';
        self._nodeList['root.lb_title'].setString("玩家" + nickname + "正在抓码");

        var paiArr = data['pai_arr'];
        var tmpPaiArr = [];
        for (var i = 0; i < 6; i++) {
            if (paiArr[i] > 0) {
                tmpPaiArr.push(paiArr[i]);
            }
        }
        paiArr = tmpPaiArr;
        var paiDelta = (6 - paiArr.length) * 46;
        for (var i = 0; i < paiArr.length; i++) {
            if (i >= 6)
                break;
            var pai = self._nodeList['root.' + i];
            var paiName = 'p2l' + paiArr[i] + '.png';
            setSpriteFrameByName(pai, paiName, majiang_hn.res.pai_hn_plist);
            pai.runAction(cc.sequence(cc.delayTime(i * A), cc.fadeIn(B)));
            pai.setPositionX(pai.getPositionX() + paiDelta);
        }

        TouchUtil.setOnclickListener(this._nodeList['root.CommonBg4._btn_back'], function () {
            if (callback) {
                callback();
            }
            network.start();
            self.removeFromParent(true);
        });

        this.scheduleOnce(function () {
            if (callback) {
                callback();
            }
            network.start();
            self.removeFromParent(true);
        }, timeout);
    },
});